﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel._Admin.SysSmsAuthLogVms
{
    public partial class SysSmsAuthLogListVm : BasePagedListVM<SysSmsAuthLogView, SysSmsAuthLogSearcher>
    {
        protected override IEnumerable<IGridColumn<SysSmsAuthLogView>> InitGridHeader()
        {
            return new List<GridColumn<SysSmsAuthLogView>>
            {
                this.MakeGridHeader(x => x.Phone),
                this.MakeGridHeader(x => x.Context),
                this.MakeGridHeader(x => x.State),
                this.MakeGridHeader(x => x.Message),
                this.MakeGridHeader(x => x.SmsTime),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysSmsAuthLogView> GetSearchQuery()
        {
            var query = DC.Set<SysSmsAuthLog>()
                .CheckContain(Searcher.Phone, x => x.Phone)
                .CheckContain(Searcher.Context, x => x.Context)
                .CheckEqual(Searcher.State, x => x.State)
                .CheckContain(Searcher.Message, x => x.Message)
                .CheckBetween(Searcher.SmsTime?.GetStartTime(), Searcher.SmsTime?.GetEndTime(), x => x.SmsTime,
                    includeMax: false)
                .Select(x => new SysSmsAuthLogView
                {
                    ID = x.ID,
                    Phone = x.Phone,
                    Context = x.Context,
                    State = x.State,
                    Message = x.Message,
                    SmsTime = x.SmsTime,
                })
                .OrderByDescending(x => x.SmsTime);
            return query;
        }
    }

    public class SysSmsAuthLogView : SysSmsAuthLog
    {
    }
}